package vn.hanelsoft.newsduet.model.helper;

import java.io.IOException;

import vn.hanelsoft.newsduet.model.object.ObjectNews;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;

public class DBHandler {

	//_________________ DB
	public static void initdb(Context context) {
		DBHelper mDBHelper = new DBHelper(context);
		try {
			mDBHelper.createDataBase();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	//________________________ News
	public static Cursor getNewsById(Context context, int id) {
		DBHelper mDBHelper = new DBHelper(context);
		Cursor cursor = mDBHelper.getNewsById(id);
		return cursor;
	}
	
	public static Cursor getNewsByCategoryId(Context context, int categoryId) {
		DBHelper mDBHelper = new DBHelper(context);
		Cursor cursor = mDBHelper.getNewsById(categoryId);
		return cursor;
	}
	
	public static Cursor getNewsByFavourite(Context context) {
		DBHelper mDBHelper = new DBHelper(context);
		Cursor cursor = mDBHelper.getNewsByFavourite();
		return cursor;
	}
	
	public static void insertNews(Context context, String categoryId, String newsLink, String newsImageSRC, String newsDescription, String newsPubDate, String favourite) {
		DBHelper mDBHelper = new DBHelper(context);
		mDBHelper.insertNews(categoryId, newsLink, newsImageSRC, newsDescription, newsPubDate, favourite);
		Log.d("Luong", "Luong________________________ save db sucess");
	}
	
	public static void deleteNewsById(Context context, int id) {
		DBHelper mDBHelper = new DBHelper(context);
		mDBHelper.deleteNewsById(id);
	}
	
	public static void deleteNewsByCategoryId(Context context, String categoryId) {
		DBHelper mDBHelper = new DBHelper(context);
		mDBHelper.deleteNewsByCategoryId(categoryId);
	}
	
	public static void deleteNewsByObjectNews(Context context, ObjectNews objectNews) {
		DBHelper mDBHelper = new DBHelper(context);
		mDBHelper.deleteNewsByObjectNews(objectNews);
	}
	
	public static void updateNewsFavourite(Context context, int id, String favourite) {
		DBHelper mDBHelper = new DBHelper(context);
		mDBHelper.updateNewsFavourite(id, favourite);
	}

}
